package efi.easycooking;

import utils.Utils;
import efi.easycooking.R;

import efi.easycooking.bo.BaseResponse;
import efi.easycooking.bra.BraMainActivity;
import efi.easycooking.eng.EngMainActivity;
import efi.easycooking.esp.EspMainActivity;
import efi.easycooking.fre.FreMainActivity;
import efi.easycooking.rest.ApiService;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.Spinner;

public class MainActivity extends Activity {

	private static String TAG = "MainActivity";
	private String imeiActual = "";

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_layout);

		Utils utils = new Utils(this);
		imeiActual = utils.getIMEI();
		
		
		ImageButton ibSalir=(ImageButton)findViewById(R.id.ibSalirA1);		
		ibSalir.setOnClickListener(new View.OnClickListener() {
		    public void onClick(View v) {
		    	
		    	finish();
		    }
		});
		
		
		GridView gv = (GridView) findViewById(R.id.gridView);		
		// this.RegistrarDevice();
		// ejemploDeLlamadaAlAPI();
		
		
		//this.Inciarservicio();
		
		gv.setAdapter(new ImageAdapter(this));
		gv.setOnItemClickListener(new OnItemClickListener() 
		{
			@Override
			public void onItemClick(AdapterView<?> parentView, View iv,int position, long id) 
			{
				Intent i;
				switch (position) 
				{
					case 0:
						i = new Intent(getApplicationContext(), EspMainActivity.class);
						startActivity(i);
						
						break;
	
					case 1:
						i = new Intent(getApplicationContext(), BraMainActivity.class);
						startActivity(i);
						break;
	
					case 2:
						i = new Intent(getApplicationContext(), EngMainActivity.class);
						startActivity(i);
						break;
	
					case 3:
						i = new Intent(getApplicationContext(), FreMainActivity.class);
						startActivity(i);
						
						break;
	
				}

			}

		});

	}

	private void Inciarservicio() {
		if (Utils.serviceStart) {
			getApplicationContext().startService(
					new Intent(this, LocationService.class));
		}
	}

	// private void ejemploDeLlamadaAlAPI() {

	// new Thread() {
	// public void run() {
	// ApiService apiService = new ApiService();
	//
	//
	// NearLocationPointsResponse locationPointsResponse = null;
	// try {
	// locationPointsResponse = apiService
	// .getNearLocationPoints(25.158, 30.588);
	// } catch (ApiServiceException e) {
	// // TODO Auto-generated catch block
	// Log.e("ERROR LLAMADO", e.getMessage());
	// e.printStackTrace();
	// }
	// if (locationPointsResponse.getCode().equals("000")) {
	// for (LocationPoint locationPoint : locationPointsResponse
	// .getList()) {
	// Log.i("TEST", locationPoint.getLatitude() + " - "
	// + locationPoint.getLongitude());
	// }
	// } else if (locationPointsResponse.getCode().equals("600")) {
	// Log.i("Test",
	// "No encontre nada en un radio de 5 kilomestros");
	// }
	// }
	// }.start();
	//
	// }

	@Override
	public void onBackPressed() {
		Log.d(this.getLocalClassName(), "onBackPressed()");
		this.finish();
	}
}